//
//  PerfectView1.m
//  fitnessmanage
//
//  Created by 众拳科技 on 2017/11/17.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "PerfectView1.h"

@implementation PerfectView1

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.backgroundColor = CSWhiteColor;
        
        /**
         绑定手机号
         */
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"您的性别是?";
        titleLabel.font = BoldBigFont;
        titleLabel.textColor = CSColorFromRGB(0x0a0a0a);
        [self addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        /**
         男
         */
        UIButton *manBtn = [[UIButton alloc] init];
        manBtn.selected = NO;
        [manBtn addTarget:self action:@selector(manBtnClick:)forControlEvents:UIControlEventTouchUpInside];
        [manBtn setImage:[UIImage imageNamed:@"boy"] forState:UIControlStateNormal];
        [manBtn setImage:[UIImage imageNamed:@"boy-choose"] forState:UIControlStateSelected];
        [manBtn setTitleColor:CSBlackColor forState:UIControlStateNormal];
        [manBtn setTitle:@"男" forState:UIControlStateNormal];
        manBtn.titleLabel.font = MidBigFont;
        [self addSubview:manBtn];
        self.manBtn = manBtn;
        
        
        /**
         女
         */
        UIButton *womanBtn = [[UIButton alloc] init];
        womanBtn.selected = NO;
        [womanBtn addTarget:self action:@selector(woManBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [womanBtn setImage:[UIImage imageNamed:@"girl"] forState:UIControlStateNormal];
        [womanBtn setImage:[UIImage imageNamed:@"girl-choose"] forState:UIControlStateSelected];
        [womanBtn setTitleColor:CSBlackColor forState:UIControlStateNormal];
        [womanBtn setTitle:@"女" forState:UIControlStateNormal];
        womanBtn.titleLabel.font = MidBigFont;
        [self addSubview:womanBtn];
        self.womanBtn = womanBtn;
        
        
        /**
         下一步按钮
         */
        UIButton *nextBtn = [[UIButton alloc] init];
        nextBtn.backgroundColor = ButtonBackGroundColor;
        nextBtn.layer.cornerRadius = 4;
        nextBtn.layer.masksToBounds = YES;
        [nextBtn setTitle:@"注册" forState:UIControlStateNormal];
        [nextBtn setTitleColor:CSBlackColor forState:UIControlStateNormal];
        nextBtn.titleLabel.font = BigFont;
        [self addSubview:nextBtn];
        self.nextBtn = nextBtn;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    /**
     绑定手机号
     */
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.mas_equalTo(self);
        
        make.top.mas_equalTo(self).offset(30);
    }];
    
    [self.manBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.mas_equalTo(self);
        
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(60);
    }];
    
    [self.womanBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.mas_equalTo(self);
        
        make.top.mas_equalTo(self.manBtn.mas_bottom).offset(60);
    }];
    
    //下一步
    [self.nextBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(self).offset(-30);
        
        make.left.mas_equalTo(self).offset(30);
        
        make.right.mas_equalTo(self).offset(-30);
        
        make.height.mas_equalTo(50);
    }];
    
    [self.manBtn titleBelowTheImageWithSpace:15];
    
    [self.womanBtn titleBelowTheImageWithSpace:15];
}


-(void)manBtnClick:(UIButton *)btn{
    
    self.womanBtn.selected = NO;
    
    self.manBtn.selected = YES;
}

-(void)woManBtnClick:(UIButton *)btn{
    
    self.womanBtn.selected = YES;
    
    self.manBtn.selected = NO;
}

@end
